package com.lingying.caiwudailikehudaun.mapper.wenJianJiaoJie;

import com.lingying.caiwudailikehudaun.domain.wenJianJiaoJie.WenJianJiaoJieBean;
import com.lingying.caiwudailikehudaun.domain.wuPinJiaoJie.UploadFileBean;
import com.lingying.caiwudailikehudaun.domain.zuoZhangShenBaoBean.ZuoZhangShenBaoBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface WenJianJiaoJieMapper {

    /**
     * 新增新文件  桑满20210607
     * @param wenJianJiaoJieBean
     * @return
     */
    @Insert("INSERT INTO  uploadFile (fileName,randomName,filePath,createTime) VALUES (#{fileName},#{randomName},#{filePath},#{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "uploadFileId")
    Integer uploadFile(UploadFileBean wenJianJiaoJieBean);

    /**
     * 查询当前选择的公司信息  桑满20210607
     * @param zuoZhangShenBaoId
     * @return
     */
    @Select("select companyName, daiLiShangCid from ZuoZhangShenBao where zuoZhangShenBaoId=#{zuoZhangShenBaoId}")
    ZuoZhangShenBaoBean queryCompanyName(Integer zuoZhangShenBaoId);

    /**
     * 添加文件交接  桑满20210607
     * @param wenJianJiaoJieBean
     * @return
     */
    @Insert("insert into wenJianJiaoJie(wenJian,xiangQing,zuoZhangShenBaoId,companyName,daiLiShangCid,tiJiaoRenName,jiGouId,tiJiaoRenPhone,fileName,tiJiaoRenShenFen) " +
            "value(#{wenJian},#{xiangQing},#{zuoZhangShenBaoId},#{companyName},#{daiLiShangCid},#{tiJiaoRenName},#{jiGouId},#{tiJiaoRenPhone},#{fileName},${2})")
    @Options(useGeneratedKeys = true , keyProperty = "wenJianJiaoJieId",keyColumn = "wenJianJiaoJieId")
    Integer addWenJianJiaoJie(WenJianJiaoJieBean wenJianJiaoJieBean);

    /**
     * 更新文件表中当前上传的文件 和文件交接表绑定  桑满20210607
     * @param wenJianJiaoJieId
     * @param uploadFileId
     * @param zuoZhangShenBaoId
     * @return
     */
    @Update("UPDATE uploadFile SET wenJianJiaoJieId = #{wenJianJiaoJieId} WHERE uploadFileId = #{uploadFileId}")
    Integer updateWuPinId(Integer wenJianJiaoJieId, Integer uploadFileId, Integer zuoZhangShenBaoId);

//    @Select("select filePath from uploadFile where uploadFileId=#{uploadFileId}")
//    String queryUploadUrl(Integer uploadFileId);

    /**
     * 文件列表数据查询回显  桑满20210608
     * @param phone
     * @param xiangQing
     * @param pages
     * @param limit
     * @return
     */
    @Select("<script>" +
            "select * from wenJianJiaoJie where tiJiaoRenPhone=#{phone} and zuoZhangShenBaoId=#{zuoZhangShenBaoId}" +
            "<if test=\"xiangQing!=null and xiangQing!=''\">" +
            " and xiangQing like CONCAT('%', #{xiangQing}, '%')" +
            "</if>" +
            " ORDER BY createTime DESC limit #{pages},#{limit}" +
            "</script>")
    List<WenJianJiaoJieBean> queryWenJianJiaoJie(String phone, Integer zuoZhangShenBaoId, String xiangQing, Integer pages, Integer limit);

    /**
     * 文件列表数据查询回显  桑满20210608
     * @param phone
     * @param xiangQing
     * @return
     */
    @Select("<script>" +
            "select count(1) from wenJianJiaoJie where tiJiaoRenPhone=#{phone} and zuoZhangShenBaoId=#{zuoZhangShenBaoId}" +
            "<if test=\"xiangQing!=null and xiangQing!=''\">" +
            " and xiangQing like CONCAT('%', #{xiangQing}, '%')" +
            "</if>" +
            "</script>")
    Integer queryWenJianJiaoJieCount(String phone, Integer zuoZhangShenBaoId, String xiangQing);
}














